<template>
  <div class="container">
    <header class="header flex">
      <div class="logo"></div>
      <div @click="switchNav(item.path)" :class="index == activeNav ? 'active' : ''" class="nav-item" v-for="(item,index) in nav" :key="index">{{ item.title }}</div>
      <div class="flex-1">
        <el-popover placement="top-start" width="360" ref="popover" trigger="hover">
          <div class="popover">
            <p class="title clearFix">
              <span>登录信息</span>
              <span class="fr" @click="$router.push('/index/accountSetting')">账户设置</span>
            </p>
            <p>• 本次登录：{{ loginData[0].operateTime }}</p>
            <p>• 登录地区：广东省深圳市 (IP：{{ loginData[0].ip }})</p>
            <p>• 上次登录：{{ loginData[1].operateTime }}</p>
          </div>
        </el-popover>
        <img class="avatar" :src="userInfo.imgUrl + userInfo.merchantLogo || '@/assets/headpto.png'" alt="" title="头像">
        <span v-popover:popover>{{ userInfo.merchantName }}</span>
        <img src="@/assets/icon-index.png" title="回到首页" @click="linkIndex">
        <img @click="loginOut" src="@/assets/icon-exit.png" title="退出">
      </div>
    </header>
    <div class="main" :style="{ 'height': mainHeight + 'px' }">
        <!--<el-menu :router="true">
          <div v-for="(item, index) in menu" :key="index">
            <p class="menu-title">{{ item.sub }}</p>
            <el-menu-item v-for="(child, idx) in item.menu" :key="idx" :index="child.path">
              <span slot="title">{{ child.name }}</span>
            </el-menu-item>
          </div>
        </el-menu>-->
      <div class="menu">
        <ul v-for="(item,index) in menu" :key="index">
          <li class="menu-item menu-title">{{ item.sub }}</li>
          <router-link active-class="active" tag="li" class="menu-item" v-for="(child,idx) in item.menu" :key="idx" :to="child.path">{{ child.name }}</router-link>
        </ul>
      </div>
      <div class="content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
  import nav from "@/utils/nav"
  import {mapState} from 'vuex';
  export default {
    name: "index",
    computed: {
      activeNav(){
        return this.$store.getters.activeNav
      },
      menu(){
        return nav[this.$store.getters.activeNav].child
      },
      userInfo(){
        return JSON.parse(this.$store.getters.userInfo);
      }
    },
    data(){
      return {
        mainHeight: window.innerHeight - 90,
        nav: nav,
        loginData: [{},{}],
      }
    },
    mounted(){
      this.$http.post("merchant/get_merchant_login_info_list", {
        currentPage: 1,
        pageSize: 10,
        orderBy: 'operate_time desc'
      }, {type: 'form'}).then((res) => {
        this.loginData = res.list;
      })
    },
    methods: {
      switchNav(path){
        this.$router.push(path);
      },
      loginOut(){
        this.$router.push('/');
        this.$store.commit("CLEAR_USERINFO");
      },
      linkIndex(){
        this.$router.push('/index')
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import "~@/assets/css/common";
  .container{
    position: fixed;
    width: 100vw;
    height: 100vh;
    left: 0;
    top: 0;
    overflow: auto;
  }
  .header{
    width: 100%;
    min-width: 1240px;
    height: 90px;
    background-color: #5BC0BF;
    .logo{
      width: 200px;
      height: 100%;
    }
    .nav-item{
      line-height: 90px;
      padding: 0 20px;
      color: #fff;
      font-size: 20px;
      cursor: pointer;
    }
    .active{
      background-color: #7CCDCC;
    }
    .flex-1{
      display: flex;
      align-items: center;
      justify-content: flex-end;
      padding-right: 30px;
      .avatar{
        width: 40px;
        height: 40px;
        border-radius: 50%;
      }
      *{
        margin-left: 20px;
      }
      span{
        color: #fff;
        font-size: 18px;
      }
    }
  }
  .main{
    display: flex;
    width: 100%;
    .menu{
      width: 200px;
      height: 100%;
      flex-shrink: 0;
      overflow: auto;
      .menu-title{
        color: #B9B9BA !important;
        cursor: auto !important;
      }
      .menu-item{
        display: block;
        line-height: 60px;
        color: #595757;
        text-align: center;
        background-color: #EFEFEF;
        box-sizing: border-box;
        cursor: pointer;
      }
      .active{
        color: #5BC0BF;
        border-bottom: 1px solid #5BC0BF;
        background-color: #fff;
      }
    }
    .content{
      position: relative;
      flex: 1;
      min-width: 1040px;
      overflow: auto;
    }
  }
  .el-menu{
    border: none;
  }
  .popover{
    padding-bottom: 20px;
    .title{
      padding: 10px;
      border-bottom: 1px solid #dddddd;
      .fr{
        color: $green;
        cursor: pointer;
      }
    }
    p:not(:first-child){
      font-size: 14px;
      margin-top: 20px;
    }
  }
</style>
